﻿using System;
using System.Collections.Generic;
using AMM.Business.Business;
using AMM.Model.Business;

namespace AMM.Forms.Reports.ReportUserControls {
    public partial class ProduceConductCostReportSearchControl : BaseReportSearchControl {

        public override string ReportName {
            get { return "ProduceConductCostReport.rdlc"; }
        }

        public override object CrossedThreadOperation() {
            string produceConductValue = Convert.ToString(this.ddlProduceConductCode.SelectedValueEx);

            return this._reportProcessor.GetProduceConductCostViewList(produceConductValue);
        }

        public override void ResetSearch() {
            this.ddlProduceConductCode.SelectedValueEx = null;
        }

        public ProduceConductCostReportSearchControl() {
            this.InitializeComponent();
        }

        private void BindProduceConduct() {
            ProduceConductSearchModel searchModel = new ProduceConductSearchModel() { IsLocked = true };
            ProduceConductProcessor produceConductProcessor = new ProduceConductProcessor(int.MaxValue);
            List<ProduceConductViewModel> produceConductList = produceConductProcessor.FetchProduceConductViewModelList(searchModel);

            this.ddlProduceConductCode.DisplayMemberEx = "ProduceConductCode";
            this.ddlProduceConductCode.ValueMemberEx = "ProduceConductCode";
            this.ddlProduceConductCode.HeightEx = 300;
            this.ddlProduceConductCode.WidthEx = 400;
            this.ddlProduceConductCode.PageSizeEx = 20;
            this.ddlProduceConductCode.DataBind(new ProduceConductViewModel(), x => new { x.ProduceConductCode, x.ProductCode }, produceConductList);

            if (produceConductList.Count > 0 && this.ddlProduceConductCode.SelectedValueEx == null) {
                this.ddlProduceConductCode.SelectedValueEx = produceConductList[0].ProduceConductCode;
            }
        }

        private void ProduceConductCostReportSearchControl_Load(object sender, EventArgs e) {
            this.BindProduceConduct();
        }
    }
}
